/**
 * Created by maiseries on 2018/1/10.
 */
import Request from '../utils/Request'
import SystemService from '../services/System'

export default class Manager {

    static MANAGER_AUDIT_STATE = {
        INIT: '09',
        UN_AUTH: '08',
        APPROVING: '01',
        PASSED: '02',
        REJECTED: '03'
    };

    static MANAGER_SUCCESS_POPUP = {
        INIT: '02',
        SHOW: '01'
    }

    static async upload(options) {

        options.url = '/manager/upload';
        try {
            const res = await Request.upload(options);
            const data = Request.valid(res);
            return {
                result: true,
                message: '成功',
                data
            }
        }catch (err){
            return {
                result: false,
                message: err.message
            }
        }
    }

    static async summary() {
        let options = {};
        options.url = '/manager/summary';
        try {
            const res = await Request.token(options);
            const data = Request.valid(res) ? Request.valid(res) : {};
            data.audit_state = data && data.audit_state ? data.audit_state : this.MANAGER_AUDIT_STATE.UN_AUTH;
            return {
                result: true,
                message: '成功',
                data
            }
        }catch (err){
            return {
                result: false,
                message: err.message
            }
        }

    }

    static async detail() {
        let options = {};
        options.url = '/manager/detail';
        try {
            const res = await Request.token(options);
            const _data = Request.valid(res);
            _data.assetManager = _data.assetManager ? _data.assetManager : {};
            const {data} = await SystemService.getIndustry();
            _data.industry = data.industry;
            _data.region = SystemService.getRegion();
            _data.assetManager.audit_state = _data && _data.assetManager && _data.assetManager.audit_state ? _data.assetManager.audit_state : this.MANAGER_AUDIT_STATE.INIT;
            return {
                result: true,
                message: '成功',
                data: _data
            }
        }catch (err){
            return {
                result: false,
                message: err.message
            }
        }
    }

    static async baseSubmit(options) {
        options.url = '/manager/base_submit';
        try {
            const res = await Request.token(options);
            Request.valid(res);
            return {
                result: true,
                message: '成功',
            }
        }catch (err){
            return {
                result: false,
                message: err.message
            }
        }
    }

    static async contactSubmit(options) {
        options.url = '/manager/contact_submit';
        try {
            const res = await Request.token(options);
            Request.valid(res);
            return {
                result: true,
                message: '成功',
            }
        }catch (err){
            return {
                result: false,
                message: err.message
            }
        }
    }

    static async imageSubmit(options) {
        options.url = '/manager/image_submit';
        try {
            const res = await Request.token(options);
            Request.valid(res);
            return {
                result: true,
                message: '成功',
            }
        }catch (err){
            return {
                result: false,
                message: err.message
            }
        }
    }

    static async submit() {
        let options = {};
        options.url = '/manager/auth';
        try {
            const res = await Request.token(options);
            Request.valid(res);
            return {
                result: true,
                message: '提交认证成功',
            }
        }catch (err){
            return {
                result: false,
                message: err.message
            }
        }
    }
}